<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<form id="id1" onsubmit="return fun()">
    用户名:<input type="text" id="name">
    <br />
    <input type="submit" value="提交">
</form>
<script>
    function fun(){
        var name = document.getElementById("name");
        if(name.value.length<3){
            alert("name不能小于3");
            return false;
        }else{
            return true;
        }
    }
</script>
</body>
</html>
